public class Solution {
    public int[] countBits(int num) {
        int[] c = new int[num + 1];
        c[0] = 0;
        int t;
        int bitt = 0x00000001;
        int tc = 0;
        for(int i = 1; i <= num; i++) {
            if(i % 2 == 0) {
                //偶数的时候
                t = i - 1;
                for(int j = 0; j < 31; j++) {
                    if((t & bitt) == 1) {
                        tc++;
                        t >>= 1;
                    } else {
                        break;
                    }
                }
                c[i] = c[i - 1] - (tc - 1);
                tc = 0;
            } else {
                //奇数的时候
                c[i] = c[i - 1] + 1;
            }
        }
        return c;
    }
}